//
//  MiaoShaViewController.m
//  1243
//
//  Created by ym on 16/6/27.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "MiaoShaViewController.h"
#import "MiaoShaTableViewCell.h"
#import "MiaoShaNeiRongViewController.h"
@interface MiaoShaViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@end

@implementation MiaoShaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"限时秒杀";
    self.navigationController.navigationBar.translucent = NO;
    [self creatTitleView];
    [self creatLunbO];
    [self creatTableView];
}

// 时间按钮
- (void)creatTitleView{
    NSArray *timeLabel = @[@"8:00",@"12:00",@"16:00",@"20:00",@"22:00",@"24:00"];
    NSArray *attitLabel = @[@"抢购限时中",@"即将开场",@"即将开场",@"即将开场",@"即将开场",@"即将开场"];
    
    UIScrollView *scorllView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
    [self.view addSubview:scorllView];
    scorllView.backgroundColor = [UIColor orangeColor];
    scorllView.contentSize = CGSizeMake((WIDTH / 4) * timeLabel.count  +30, 50);// x,y 任何小于375 667 都不能滚动
    scorllView.showsVerticalScrollIndicator = NO;
    scorllView.showsHorizontalScrollIndicator = NO;
    
    
    for (NSInteger i =  0; i < timeLabel.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setBackgroundColor:[UIColor redColor]];
        btn.frame = CGRectMake(0 +( WIDTH/4 ) *i, 0, WIDTH/5, 50);
        [scorllView addSubview:btn];
        
        UILabel *time = [[UILabel alloc] init];
        time.frame = CGRectMake(0, 0, btn.frame.size.width, btn.frame.size.height/3 *2);
        [btn addSubview:time];
        time.text = timeLabel[i];
        time.font = [UIFont systemFontOfSize:18];
        time.textAlignment = NSTextAlignmentCenter;
        
        UILabel *attit = [[UILabel alloc] init];
        attit.frame = CGRectMake(0,  btn.frame.size.height/3 *2 - 10, btn.frame.size.width, btn.frame.size.height/3 );
        [btn addSubview:attit];
        attit.text = attitLabel[i];
        attit.font = [UIFont systemFontOfSize:13];
        attit.textAlignment = NSTextAlignmentCenter;
    }
    
}


- (void)creatLunbO{
    NSArray *image = @[
                       
                       [UIImage imageNamed:@"bot_1"],
                       [UIImage imageNamed:@"banner_bot1_boom"],
                       [UIImage imageNamed:@"bot_2"],
                       [UIImage imageNamed:@"bot_3"]
                       ];
    UIScrollView *scorllView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, WIDTH, 180)];
    scorllView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:scorllView];
    // 边缘弹动 效果 bounces
    scorllView.bounces = NO;
    // 整页翻动 pagingEnable
    scorllView.pagingEnabled = YES;
    // 允许滚动
    scorllView.scrollEnabled = YES;
    // 快速滚到当前页面顶端 (点击状态栏时) scrollToTop
    scorllView.scrollsToTop = YES;
    // 隐藏滚动条
    scorllView.showsHorizontalScrollIndicator = YES;  //横向
    scorllView.showsVerticalScrollIndicator = YES;   // 纵向s
    // 自定义滚动条样式
    scorllView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
     scorllView.contentSize = CGSizeMake(WIDTH * image.count, 180);

    for (NSInteger i = 0; i < image.count; i++) {
        UIImageView *a = [[UIImageView alloc] init];
        [scorllView addSubview:a];
        a.image = image[i];
        a.frame = CGRectMake(WIDTH *i, 0, WIDTH, 180);
    }
    
}
- (void)creatTableView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 230, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.rowHeight = 100;
    
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier= @"MiaoShaTableViewCell";
    
    MiaoShaTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell==nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MiaoShaTableViewCell" owner:nil options:nil] lastObject];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 200;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MiaoShaNeiRongViewController *a = [[MiaoShaNeiRongViewController alloc] init];
    [self pushForm:self.navigationController pushToAndHidden:a];
    
}

//tabBar 隐藏
- (void)pushForm:(UINavigationController *)pushForm pushToAndHidden:(UIViewController *)pushToVC
{
    [pushToVC setHidesBottomBarWhenPushed:YES];
    [pushForm pushViewController:pushToVC animated:YES];
    
}













@end
